package com.sbm.datasource.dynamic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sbm.datasource.config.CustomDataSourceConfig;
import com.sbm.datasource.config.DefaultDataSourceConfig;

import lombok.Data;

@Data
@Component
public class DynamicDataSourceConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(DynamicDataSourceConfig.class);

    @Autowired
    private DefaultDataSourceConfig defaultDataSourceConfig;

    @Autowired
    private CustomDataSourceConfig customDataSourceConfig;

    public void initialize() {
        try {
            LOGGER.info("————初始化数据源配置——");
            defaultDataSourceConfig.initConfig();
            customDataSourceConfig.initConfig();
            LOGGER.error("配置初始化成功");
        } catch (Exception ex) {
            LOGGER.error("初始化失败：" + ex.getMessage());
            ex.printStackTrace();
        }
    }
}
